#include "Platform.h"
#include "Polygon2.h"
#include "Contour2.h"
#include "Point2.h"
#include "IoPoint2.h"
#include <iostream>

namespace Tests {
	void polygon() {
		const double h = .5;
		Point2 shapes[][4] = {
			{ // Outer contour (CCW-ordering)
				Point2( -1, -1 ),
				Point2(  1, -1 ),
				Point2(  1,  1 ),
				Point2( -1,  1 )
			}, { // Holes (CW-ordering)
				Point2( -h,  h ), 
				Point2(  0,  h ),
				Point2(  0,  0 ),
				Point2( -h,  0 )
			}, {
				Point2(  0,  0 ), 
				Point2(  h,  0 ),
				Point2(  h, -h ),
				Point2(  0, -h )
			}
		};

		Tessellator t;
		Polygon2 poly; {
			auto& lock = poly.lockContours( &t );
			auto& contours = lock.contours();
			
			// FOR ( const Point2 (&shape)[4], shapes )
			for ( int idx = 0; idx < 4; ++idx ) {
				const Point2 (&shape)[4] = shapes[idx];
				contours.push_back( Contour2( shape, shape + 4 ) );
			}
		}

		poly.tessellation().eachTriangle( [&] ( const Point2& a, const Point2& b, const Point2& c ) {
			std::cout << '[' << a << ", " << b << ", " << c << ']' << std::endl;
		} );
	}
}